<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <style>

        *{
            padding: 0;
            margin: 0;
        }
        .outer-box{
            width: 40%;
            margin: 100px auto;
        }
        .outer-box .title{
            font-size: 20px;
            font-weight: 700;
            text-align: center;
            margin: 30px;
        }
        .outer-box .block{
            width: 100%;
            margin: 20px 0;
            overflow: hidden;
        }
        .outer-box .block input{
            width: 100%;
            height: 30px;
            border-radius: 5px;
            border: 2px solid #ccc;
            box-sizing: border-box;
            padding-left: 10px;
        }
        .outer-box .block span{
            float: right;
            font-size: 14px;
            color: #ccc;
            cursor: pointer;
        }
        .outer-box .block:last-child input{
            padding: 0;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="outer-box">
        <div class="title">登录</div>
        <div class="block">
            <input type="text" placeholder="输入用户名">
        </div>
        <div class="block">
            <input type="password" placeholder="输入密码">
        </div>
        <div class="block">
            <span>忘记密码</span>
        </div>
        <div class="block">
            <input type="button" value="登录">
        </div>
    </div>
</body>
</html>
<script src="./ajax-promise.js"></script>
<script>

    const ipts = document.querySelectorAll('.outer-box .block input');
    ipts[2].onclick = ()=>{
        if(ipts[0].value && ipts[1].value){
            if(/^1[3-9]\d{9}$/.test(ipts[0].value) && /^\d{4}$/.test(ipts[1].value)){
                ajax('get','https://yantianfeng.com/api/login',{username:ipts[0].value,password:ipts[1].value}).then((res)=>{alert(res.msg);})
            }else{
                alert('用户名/密码格式错误！');
            }
        }else{
            alert('用户名/密码不能为空！');
        }
    }

</script>